#include <zephyr/types.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <zephyr/sys/printk.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/kernel.h>

#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/uuid.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/services/bas.h>
#include <zephyr/bluetooth/services/hrs.h>

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(sys_init, CONFIG_BT_LOG_LEVEL);

static K_KERNEL_STACK_DEFINE(sys_init_stack, 1024);
static struct k_thread sys_init_thread_data;
static void thread_sys_entry(void);

#if defined(CONFIG_BT)
void bt_init(void);
#endif

#if defined(CONFIG_SENSOR)
void sensor_manager_init(void);
#endif

/**
 * @description:
 * @return {*}
 */
void main(void)
{
	const k_tid_t tid =
	k_thread_create(&sys_init_thread_data, sys_init_stack,
			K_KERNEL_STACK_SIZEOF(sys_init_stack),
			(k_thread_entry_t)thread_sys_entry, NULL, NULL, NULL,
			K_PRIO_COOP(6),
			0, K_NO_WAIT);
	k_thread_name_set(tid, "sys_init");
}

/**
 * @description:
 * @return {*}
 */
static void thread_sys_entry(void)
{
	#if defined(CONFIG_BT)
	bt_init();
	#endif

	#if defined(CONFIG_SENSOR)
	sensor_manager_init();
	#endif

#if !defined(CONFIG_BT) && !defined(CONFIG_SENSOR)
	LOG_INF("%s system error\n", __func__);
#else
    LOG_INF("%s starts to run..\n", __func__);
#endif
}
